from rediscluster import StrictRedisCluster
import sys


def cluster_client():
    host = '127.0.0.1'
    redis_nodes = [{'host': host, 'port': 7000},
                   {'host': host, 'port': 7001},
                   {'host': host, 'port': 7002},
                   {'host': host, 'port': 7003},
                   {'host': host, 'port': 7004},
                   {'host': host, 'port': 7005}
                   ]
    try:
        redisconn = StrictRedisCluster(startup_nodes=redis_nodes)
    except Exception:
        print("Connect Error!")
        sys.exit(1)
    return redisconn


conn = cluster_client()


def get(key):
    v = conn.get(key)
    if isinstance(v, bytes):
        return v.decode()
    return v


def set(key, value):
    conn.set(key, value)


if __name__ == '__main__':
    print(get('ucenter:wealth:238893849'))
